home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC20DTSToolLib / FMD.asm < prev    next >
Encoding:
Assembly Source File  |  1990-06-24  |  48.8 KB  |  2,003 lines  |  [TEXT/pdos]

  1. *******************************************************************************
  2. *
  3. * fakeModalDialog and other supporting access routines and such.
  4. * Version 3.0
  5. *
  6. * Copyright (c)
  7. * Apple Computer, Inc.  1989-1990
  8. * All Rights Reserved.
  9. *
  10. * Written by Eric Soldan.
  11. *
  12. * Developer Technical Support Apple II Sample Code
  13. *
  14. * The purpose of this code is to handle dialogs in a variety of ways
  15. * that are more robust than what the toolbox offers.  It also supports
  16. * the new movable/modeless dialog types described in the latest human
  17. * interface guidelines.
  18. *
  19. * See FMD.USAGE for usage information.
  20. *
  21. *******************************************************************************
  22.  
  23.  
  24.         case on
  25.  
  26.         mcopy macros/FMD.Macros
  27.  
  28.         copy 2/ainclude/e16.types
  29.         copy 2/ainclude/e16.control
  30.         copy 2/ainclude/e16.event
  31.         copy 2/ainclude/e16.lineedit
  32.         copy 2/ainclude/e16.window
  33.  
  34.         longi on
  35.         longa on
  36.  
  37. ***********************************************************************
  38.  
  39. fmdNoScrapForLE gequ $0001
  40. fmdMenuSelect   gequ $0002
  41. fmdMenuKey      gequ $0004
  42. fmdIBeam        gequ $0008
  43. fmdDeskAcc      gequ $0010
  44. fmdUpdateAll    gequ $4000
  45. fmdMovable      gequ $8000
  46.  
  47. fakeModalDialog Start
  48.  
  49.                 DefineStack
  50.  
  51. dlgwptr         long          ;Must be at 1,s
  52. keepPort        long          ;Must be at 5,s
  53. ctlHndl         long
  54. ctlPtr          long
  55. theHndl         long
  56. thePtr          long
  57. whichWindow     long
  58. tempwptr        long
  59. code            word
  60. editTask        word
  61. yloc            word
  62. xloc            word
  63. wkind           word
  64. menunum         word
  65. zero            word
  66.  
  67. sizeFMDLocals   EndLocals
  68.  
  69. saveDPage       word
  70. returnAddr      block 3
  71.  
  72.         BegParms
  73. flags   word    ;bit 0 = 0, involve scrap for
  74. *               ;           lineEdit items.
  75. *               ;bit 0 = 1, don't involve scrap for
  76. *               ;           lineEdit items.
  77. *               ;bit 1 = 0, don't do _MenuSelect for
  78. *               ;           movable/modal dialogs.
  79. *               ;bit 1 = 1, do _MenuSelect for
  80. *               ;           movable/modal dialogs.
  81. *               ;bit 2 = 0, don't do _MenuKey for
  82. *               ;           movable/modal dialogs.
  83. *               ;bit 2 = 1, do _MenuKey for
  84. *               ;           movable/modal dialogs.
  85. *               ;bit 3 = 0, use arrow cursor
  86. *               ;           everywhere.
  87. *               ;bit 3 = 1, use i-beam cursor for
  88. *               ;           lineEdit & textEdit ctls.
  89. *               ;bit 4 = 0, let app handle desk
  90. *               ;           accessories.
  91. *               ;bit 4 = 1, automatically handle desk
  92. *               ;           accessories.
  93. *               ;bit 14 = 0, Don't update other
  94. *               ;            application windows.
  95. *               ;bit 14 = 1, Update all windows.
  96. *               ;bit 15 = 0, Modal window.
  97. *               ;bit 15 = 1, movable/modal window.
  98. beepProc        long          ;Null, SysBeep.  Negative, do nothing.
  99. eventHook       long          ;Optional -- pass a NULL for none.
  100. updateProc      long          ;Optional -- pass a NULL for default.
  101. event           long          ;Must be extended 5.0 event rec ptr.
  102. sizeFMDParms    Endparms
  103.  
  104. retval          long          ;Control ID hit.  NULL if none.
  105. *                             ;If bit 31 is on, then retval
  106. *                             ;is a menu ID.
  107. ***
  108.  
  109. FAKEMODALDIALOG entry
  110.         phd                   ;Save directPage register.
  111.         tsc                   ;Make space for locals.
  112.         sec
  113.         sbc #sizeFMDLocals
  114.         tcs
  115.         tcd                   ;Set directPage register.
  116.  
  117.         pla
  118.         pla
  119.         _GetPort              ;Result space already there (keepPort).
  120.  
  121.         pha
  122.         pha
  123.         _FrontWindow          ;Result space already there (dlgwptr).
  124.  
  125.         pha                   ;Find out if it is a DA window.
  126.         pei dlgwptr+2
  127.         pei dlgwptr
  128.         _GetWKind
  129.         pla
  130.         sta wkind
  131.         bpl gotit
  132.  
  133. get1stRegWnd anop
  134.         pha                   ;Result space for _GetWFrame.
  135.  
  136.         pha                   ;Result space for _GetNextWindow.
  137.         pha
  138.  
  139.         pei dlgwptr+2
  140.         pei dlgwptr
  141.         _GetNextWindow
  142.  
  143.         lda 1,s               ;Param for _GetWFrame.
  144.         sta dlgwptr
  145.         lda 3,s
  146.         sta dlgwptr+2
  147.  
  148.         _GetWFrame
  149.         pla
  150.  
  151.         and #fVis
  152.         beq get1stRegWnd      ;Window is invisible, so skip it.
  153.  
  154.         pha
  155.         pei dlgwptr+2
  156.         pei dlgwptr
  157.         _GetWKind
  158.         pla
  159.         bmi get1stRegWnd      ;Window is system window, so skip it.
  160.  
  161. gotit   stz retval            ;Assume nothing interesting is
  162.         stz retval+2          ;going to happen.
  163.         stz code
  164.         stz editTask          ;For cut/copy/paste/clear signal.
  165.         stz zero              ;For optimization purposes.
  166.  
  167.         lda updateProc+1      ;Set up the update procedure for all
  168.         bne FMDTemp1          ;cases.  This also sets it up so that
  169. *                             ;TaskMaster can handle this window
  170. *                             ;from other parts of the application.
  171.  
  172.         lda #fmdStdDrawProc|-16
  173.         sta updateProc+2
  174.         lda #fmdStdDrawProc
  175.         sta updateProc        ;Use the default update procedure.
  176. FMDTemp1 anop
  177.         pei updateProc+2
  178.         pei updateProc
  179.         pei dlgwptr+2
  180.         pei dlgwptr
  181.         _SetContentDraw       ;Let the window and TaskMaster know.
  182.  
  183. FMDTemp2 anop
  184.         pha                   ;Make sure that top window is
  185.         pha                   ;the active window.
  186.         _GetPort
  187.         pla
  188.         sta keepPort
  189.         pla
  190.         sta keepPort+2
  191.         pei dlgwptr+2
  192.         pei dlgwptr
  193.         _SetPort
  194.  
  195.         lda flags
  196.         and #fmdIBeam
  197.         beq FMDTemp3          ;No cursor changes.
  198.  
  199.         lda wkind
  200.         bmi FMDTemp3
  201.  
  202.         pha                   ;Result space for control part.
  203.  
  204.         ldy #0                ;Point to where to put the handle.
  205.         phy
  206.         tdc
  207.         clc
  208.         adc #ctlHndl
  209.         pha                   ;Pointer to ctlHndl now on stack.
  210.  
  211.         phy
  212.         adc #yloc-ctlHndl
  213.         pha                   ;Pointer to yloc now on stack.
  214.         _GetMouse
  215.  
  216.         pei xloc              ;Now that they are right, pass 'em on.
  217.         pei yloc
  218.         pei dlgwptr+2
  219.         pei dlgwptr
  220.         jsl fmdFindCursorCtl  ;Find which control cursor is over.
  221.         pla                   ;The part code, which we don't care
  222. *                             ;about here.
  223.  
  224.         beq arrowCursor       ;Not over any control -- use arrow.
  225.  
  226.         jsr getCtlProc        ;Find out what kind of control it is.
  227.         cmp #editTextControl|-16
  228.         beq ibeamCursor       ;It is a TextEdit ctl, kind of
  229. *                             ;See fmdFindCursorCtl for more info.
  230.         cmp #editLineControl|-16
  231.         beq ibeamCursor       ;It is a LineEdit tool.
  232.  
  233. arrowCursor anop
  234.         jsr ibeamTest
  235.         bcc FMDTemp3
  236.         _InitCursor
  237.         bra FMDTemp3          ;We have an arrow cursor.
  238.  
  239. ibeamCursor anop
  240.         jsr ibeamTest
  241.         bcs FMDTemp3           ;We have an ibeam cursor.
  242.         jsl fmdIBeamCursor
  243.  
  244. FMDTemp3 anop
  245.         _SystemTask
  246.  
  247.         lda flags             ;See if cut/copy/paste is tied to menu.
  248.         and #fmdMenuSelect+fmdMenuKey
  249.         beq FMDTemp4          ;Isn't keyDownEvt or mouseDownEvt.
  250.         jsl fmdEditMenu       ;Update the edit menu.
  251.  
  252. FMDTemp4 anop
  253.         pha                   ;Get the event.
  254.         pea $FFFF
  255.         pei event+2
  256.         pei event
  257.         _GetNextEvent
  258.         pla
  259.         beq exit              ;Event shouldn't be handled by app.
  260.  
  261.         ldy #owhat
  262.         lda [event],y
  263.         sta code
  264.         bne gotEvent
  265.  
  266. exit    lda code              ;See if code is 0.  If it is, force a
  267.         bne exit0             ;NULL event, so the cursor will flash
  268.         ldy #owhat            ;for lineedit items, etc.
  269.         sta [event],y
  270.         pha
  271.         pea 1
  272.         pha
  273.         pha
  274.         pei event+2
  275.         pei event
  276.         _SendEventToCtl
  277.         pla
  278.  
  279. exit0   pei keepPort+2
  280.         pei keepPort
  281.         _SetPort
  282.         tsc                   ;Get rid of local variables.
  283.         clc
  284.         adc #sizeFMDLocals
  285.         tcs
  286.         pld                   ;Restore directPage register.
  287.         lda 1,s               ;Move return address.
  288.         sta 1+sizeFMDParms,s
  289.         lda 2,s
  290.         sta 2+sizeFMDParms,s
  291.         tsc                   ;Get rid of passed parameters.
  292.         adc #sizeFMDParms
  293.         tcs
  294.         jml _fmdNoError
  295.  
  296. gotEvent anop
  297.         lda eventHook+1
  298.         beq noEventHook       ;Zero, no event massaging.
  299.  
  300.         pei event+2           ;Give the event hook something
  301.         pei event             ;to play with.
  302.         phk                   ;Push where we want to return to.
  303.         pea noEventHook-1
  304.  
  305.         pha                   ;Push the eventHook address and return
  306.         phb                   ;to it.
  307.         pla
  308.         lda eventHook
  309.         dec a
  310.         pha
  311.         rtl
  312.  
  313. noEventHook anop
  314.         ldy #owhat
  315.         lda [event],y
  316.         sta code
  317.  
  318.         jsr doMouseDown
  319.         bcc exit
  320.  
  321.         jsr doMenuKey
  322.         bcc exit              ;The key was a menu key.
  323.  
  324.         jsr doCutCopyPaste
  325.         bcc exit              ;We did a cut, copy, or paste.
  326.  
  327.         jsr doActivate
  328.         bcc exit              ;We did an activate.
  329.  
  330.         jsr doUpdate
  331.         bcc exit              ;We did an update.
  332.  
  333.         pha
  334.         lda #0
  335.         pha
  336.         pha
  337.         pha
  338.         pei event+2
  339.         pei event
  340.         _SendEventToCtl
  341.         pla
  342.         beq exit0
  343.  
  344.         ldy #owmTaskData2     ;Get the ctl hndl of affected ctl.
  345.         lda [event],y
  346.         sta ctlHndl           ;Save this in ctlHndl.
  347.         iny
  348.         iny
  349.         lda [event],y
  350.         sta ctlHndl+2
  351.         jsr setValues
  352.         brl exit
  353.  
  354. ***
  355.  
  356. doCutCopyPaste anop
  357.         lda editTask          ;We already have a task, 
  358.         bne ATask             ;so don't check keypress.
  359.  
  360.         lda code
  361.         cmp #keyDownEvt
  362.         beq akey
  363.         cmp #autoKeyEvt
  364.         beq akey
  365.  
  366. CCPsecexit anop
  367.         sec
  368.         rts
  369.  
  370. akey    lda flags
  371.         and #fmdMenuKey
  372.         bne CCPsecexit
  373.         ldy #omodifiers       ;See if it is a cut/copy/paste command.
  374.         lda [event],y
  375.         and #controlKey+optionKey+appleKey
  376.         cmp #appleKey
  377.         bne CCPsecexit        ;Wrong modifiers -- no go.
  378.  
  379.         ldy #omessage
  380.         lda [event],y
  381.         ora #$20              ;Lower-case it.
  382.  
  383.         ldx #251
  384.         cmp #'x'
  385.         beq GotEditTask
  386.         inx
  387.         cmp #'c'
  388.         beq GotEditTask
  389.         inx
  390.         cmp #'v'
  391.         sec
  392.         bne CCPsecexit
  393. GotEditTask anop
  394.         stx editTask          ;We have a valid task now.
  395.  
  396. ATask   pha                   ;Find out what control we are talking
  397.         pha                   ;about.
  398.         _FindTargetCtl
  399.         ply
  400.         sty ctlHndl
  401.         ply
  402.         sty ctlHndl+2
  403.         bcs CCPsecexit
  404.  
  405.         lda editTask          ;251 thru 254 (cut/copy/paste/clear)
  406.         stz editTask          ;This is also a flag, so we need to set
  407.         sec                   ;it back.
  408.         sbc #251-4
  409.         asl a                 ;Assume TextEdit.
  410.         tax
  411.         stz theHndl     
  412.         stz theHndl+2
  413.  
  414.         jsr getCtlProc        ;Find out what tool it is.
  415.         cmp #editTextControl|-16
  416.         beq FMDTemp5          ;It is TextEdit, and the xreg is set up
  417. *                             ;for TextEdit.
  418.  
  419.         cmp #editLineControl|-16
  420.         bne CCPsecexit        ;Not a LineEdit tool, so there can be
  421. *                             ;no cut/copy/paste.
  422.  
  423.         ldy #octlData         ;It is LineEdit.
  424.         lda [ctlPtr],y
  425.         sta theHndl
  426.         iny
  427.         iny
  428.         lda [ctlPtr],y
  429.         sta theHndl+2
  430.         txa
  431.         and #7
  432.         tax                   ;LineEdit tool.
  433.  
  434. FMDTemp5 anop
  435.         pei theHndl+2         ;All the below routines will use this
  436.         pei theHndl           ;parameter eventually.
  437.         jmp (theTask,x)
  438.  
  439. theTask dc i'leCut, leCopy, lePaste, leClear'
  440.         dc i'teCut, teCopy, tePaste, teClear'
  441.  
  442. leCut   _LECut                ;Do the cut.
  443. leCut0  lda flags
  444.         lsr a
  445.         bcs CCPclcexit
  446.         _ZeroScrap            ;Then conditionally do the LEToScrap.
  447.         pha                   ;Conditionally, because of the bug for
  448.         _LEGetScrapLen        ;zero-length scrap.
  449.         pla
  450.         beq CCPclcexit
  451.         _LEToScrap
  452. CCPclcexit anop
  453.         clc                   ; clc and exit for Cut/Copy/Paste
  454.         rts
  455. CCPclcexitz anop
  456.         pla                   ; z routine pulls two words first
  457.         pla
  458.         clc
  459.         rts
  460.  
  461. leCopy  _LECopy               ;Do the copy.
  462.         bra leCut0
  463.  
  464. lePaste lda flags
  465.         lsr a
  466.         bcs FMDTemp6
  467.  
  468.         pha                   ;Boy, are we good citizens, or what?
  469.         pha
  470.         pei zero
  471.         _GetScrapSize
  472.         plx
  473.         ply
  474.         bcs CCPclcexitz       ;Give up and do nothing.
  475.         tya
  476.         bne CCPclcexitz       ;Way too big, so give up.
  477.         txa
  478.         beq CCPclcexitz       ;Too small, so give up.
  479.         _LEFromScrap
  480.         bcs CCPclcexitz       ;Somebody wasn't pleased, so give up.
  481. FMDTemp6 anop
  482.         _LEPaste
  483.         clc
  484.         rts
  485.  
  486. leClear _LEDelete             ;Do the clear.
  487.         clc
  488.         rts
  489.  
  490. teCut   ldy #$28+2
  491.         lda [ctlPtr],y
  492.         and #$0400
  493.         beq teCut0
  494.         pla
  495.         pla
  496.         bra teCut1
  497. teCut0  _TECut                ;Do the cut.
  498. teCut1  clc
  499.         rts
  500.  
  501. teCopy  _TECopy               ;Do the copy.
  502.         clc
  503.         rts
  504.  
  505. tePaste _TEPaste              ;Do the paste.
  506.         clc
  507.         rts
  508.  
  509. teClear _TEClear              ;Do the clear.
  510.         clc
  511.         rts
  512.  
  513. getCtlProc anop
  514.         ldy #2                ;Find out what tool it is.
  515.         lda [ctlHndl],y
  516.         sta ctlPtr+2
  517.         lda [ctlHndl]
  518.         sta ctlPtr            ;Handle now dereferenced.
  519.         ldy #octlProc+2       ;Get hi-word of proc address.
  520.         lda [ctlPtr],y
  521.         rts
  522.  
  523. ***
  524.  
  525. doActivate anop
  526.         lda code
  527.         cmp #activateEvt
  528.         beq FMDTemp7
  529.         sec
  530.         rts
  531.  
  532. FMDTemp7 anop
  533.         pha
  534.         pha
  535.         _GetPort
  536.  
  537.         pha                   ;Result space for _GetWControls.
  538.         pha
  539.         ldy #omessage+2       ;Find out which window we are
  540.         lda [event],y         ;talking about.
  541.         tax
  542.         dey
  543.         dey
  544.         lda [event],y
  545.         phx
  546.         pha
  547.         phx
  548.         pha
  549.         _SetPort
  550.  
  551.         ldy #omodifiers       ;See if we are activating.
  552.         lda [event],y
  553.         lsr a
  554.         bcc noMenuProc        ;We are not, so don't update menus.
  555.  
  556.         pha                   ;See if we have a proc to set the state
  557.         pha                   ;of the menus.
  558.         jsl fmdGetMenuProc
  559.         plx                   ;Lo-word of address.
  560.         pla                   ;Hi-word of address.
  561.         bne haveMenuProc      ;We have a menu Proc -- go do it.
  562.         txy
  563.         beq noMenuProc        ;We don't have one.
  564.  
  565. haveMenuProc anop
  566.         phk                   ;Push where we want to return to.
  567.         pea noMenuProc-1
  568.         xba                   ;Push just the lo-byte as the hi-byte
  569.         pha                   ;of ret addr.
  570.         phb
  571.         pla
  572.         dex                   ;Push the lo-word minus 1 for rtl.
  573.         phx
  574.         rtl
  575.  
  576. noMenuProc anop
  577.         _GetWControls
  578.         pla
  579.         sta ctlHndl
  580.         pla
  581.         sta ctlHndl+2
  582.  
  583. FMDLoop1 anop
  584.         lda ctlHndl+1
  585.         beq ActivateExit
  586.         jsr getCtlProc
  587.  
  588.         ldx #nakend-nak-2
  589. naklook cmp >nak,x
  590.         beq ActivateNextCtl
  591.         dex
  592.         dex
  593.         bpl naklook
  594.  
  595.         cmp #editLineControl|-16
  596.         bne ActivateInval       ;Invalidate unless lineEdit.
  597. *                               ;Invalidate this one selectively.  If
  598. *                               ;it is the window's target, then
  599. *                               ;invalidate it.
  600.  
  601.         ldy #octlMoreFlags
  602.         lda [ctlPtr],y
  603.         bpl ActivateNextCtl     ;It doesn't need invalidating.
  604.  
  605. ActivateInval   lda ctlPtr      ;Push pointer to bounding rect of ctl.
  606.         clc
  607.         adc #octlRect
  608.         tax
  609.         lda ctlPtr+2
  610.         adc #0
  611.         pha
  612.         phx
  613.         _InvalRect
  614.         jsr getCtlProc          ;An easy way to redereference.
  615.  
  616. ActivateNextCtl anop
  617.         ldy #2
  618.         lda [ctlPtr]
  619.         sta ctlHndl
  620.         lda [ctlPtr],y
  621.         sta ctlHndl+2
  622.         bra FMDLoop1
  623.  
  624. ActivateExit anop
  625.         _SetPort
  626.         clc                     ;displayed in the correct state.
  627.         rts
  628.  
  629. nak     dc i'$8100,$8900,$8D00' ;These don't need invalidating ever.
  630. nakend  anop
  631.  
  632. ***
  633.  
  634. doUpdate anop
  635.         lda code
  636.         cmp #updateEvt
  637.         beq FMDTemp8
  638.         sec
  639.         rts                     ;Event isn't an update event.
  640.  
  641. noUpdate anop
  642.         stz code                ;We don't do this update, since the
  643.         clc                     ;window that needs to be updated isn't
  644.         rts                     ;the modal dialog.
  645.  
  646. FMDTemp8 anop
  647.         ldy #omessage+2         ;Find out which window we are
  648.         lda [event],y           ;talking about.
  649.         sta tempwptr+2
  650.         tax
  651.         dey
  652.         dey
  653.         lda [event],y
  654.         sta tempwptr
  655.         tay
  656.  
  657.         lda flags
  658.         and #fmdUpdateAll
  659.         bne realUpdate          ;We are movable/modal, so update it,
  660. *                               ;whatever it is.
  661.  
  662.         cpy dlgwptr
  663.         bne noUpdate            ;We are modal, so don't update other
  664.         cpx dlgwptr+2           ;windows.
  665.         bne noUpdate            ;We are modal, so don't update other
  666. *                               ;windows.
  667.  
  668. realUpdate anop
  669.         phx                     ;Result space for _GetContentDraw.
  670.         phy
  671.         phx                     ;For _GetContentDraw
  672.         phy
  673.         _GetContentDraw
  674.         plx
  675.         pla
  676.         bne haveProc
  677.         txy
  678.         beq UpdateExit
  679.  
  680. haveProc anop
  681.         phk                     ;Push return address for updateProc.
  682.         pea UpdateRetLoc-1
  683.  
  684.         xba                    ;Push just the lo-byte as the hi-byte
  685.         pha                    ;of ret addr.
  686.         phb
  687.         pla
  688.  
  689.         dex                    ;Push the lo-word minus 1 for rtl.
  690.         phx
  691.  
  692.         pei tempwptr+2
  693.         pei tempwptr
  694.         _BeginUpdate
  695.  
  696.         rtl                    ;Go to the updateProc.
  697.  
  698. UpdateRetLoc anop
  699.         pei tempwptr+2
  700.         pei tempwptr
  701.         _EndUpdate
  702.  
  703. UpdateExit anop
  704.         clc
  705.         rts
  706.  
  707. ***
  708.  
  709. doMouseDown anop
  710.         lda code
  711.         cmp #mouseDownEvt
  712.         beq FMDTemp9
  713.         sec
  714.         rts
  715.  
  716. FMDTemp9 anop
  717.         pha                    ;Find out what window we clicked on.
  718.         pei zero
  719.         tdc
  720.         clc
  721.         adc #whichWindow
  722.         pha
  723.         ldy #owhere+2
  724.         lda [event],y
  725.         sta xloc
  726.         pha
  727.         dey
  728.         dey
  729.         lda [event],y
  730.         sta yloc
  731.         pha
  732.         _FindWindow
  733.         pla
  734.         bpl FMDTemp9a
  735.  
  736.         tax                   ;Keep it for _SystemClick's use.
  737.         lda flags
  738.         and #fmdDeskAcc
  739.         beq MDtoBeep
  740.  
  741.         pei event+2           ;Let the DA have some fun, too.
  742.         pei event
  743.         pei whichWindow+2
  744.         pei whichWindow
  745.         phx
  746.         _SystemClick
  747.         clc
  748.         rts
  749.  
  750. FMDTemp9a anop
  751.         cmp #wInDrag
  752.         bne FMDTemp10
  753.  
  754.         jsr isMyWindow        ;See if "whichWindow" equals dlgwptr.
  755.         bcc MDtoBeep          ;Wrong window -- nice try, though.
  756.  
  757.         lda flags
  758.         bpl FMDTemp9z         ;MDnoBeep
  759.  
  760.         ldy #0                ;Drag resolution -- default.
  761.         phy
  762.         pei xloc              ;Starting mouse location.
  763.         pei yloc
  764.         pea 8                 ;TaskMaster uses this value, so we do.
  765.         phy                   ;Default cursor boundary.
  766.         phy
  767.         pei dlgwptr+2
  768.         pei dlgwptr
  769.         _DragWindow
  770.         ldy #omodifiers
  771.         lda [event],y
  772.         and #appleKey
  773.         bne FMDTemp9z
  774.         pei dlgwptr+2
  775.         pei dlgwptr
  776.         _SelectWindow
  777. FMDTemp9z anop
  778.         brl MDnoBeep
  779.  
  780. FMDTemp10 anop
  781.         cmp #wInMenuBar
  782.         bne FMDTemp11         ;Not in menu bar.
  783.         lda flags
  784.         lsr a
  785.         lsr a
  786.         bcc MDtoBeep          ;_MenuSelect not allowed -- go do beep.
  787.         lda flags
  788.         and #fmdMenuSelect+fmdMenuKey
  789.         beq MDtoBeep          ;Modal dialog, no menus allowed, so go
  790. *                             ;do beep.
  791.         brl doMenuTask        ;Movable/modal dialog, so go
  792. *                             ;handle menu bar.
  793.  
  794. FMDTemp11 anop
  795.         cmp #wInFrame         ;Don't beep if on dialog frame.  This
  796.         beq FMDTemp12         ;branch is the most efficient sizewise,
  797. *                             ;since we won't hit any controls.
  798.         cmp #wInContent
  799.         bne MDtoBeep          ;We didn't click in a content.
  800.  
  801. FMDTemp12 anop
  802.         jsr isMyWindow
  803.         bcs FMDTemp13
  804. MDtoBeep anop
  805.         brl MDBeep
  806.  
  807. FMDTemp13 anop
  808.         pha
  809.         pha
  810.         _FrontWindow
  811.         pei dlgwptr+2
  812.         pei dlgwptr
  813.         _SelectWindow
  814.  
  815.         pla
  816.         plx
  817.         cmp whichWindow
  818.         bne MDnoBeep
  819.         cpx whichWindow+2
  820.         bne MDnoBeep
  821.  
  822. FMDTemp14 anop
  823.         pha
  824.         pei zero
  825.         tdc
  826.         clc
  827.         adc #ctlHndl
  828.         pha
  829.         pei xloc
  830.         pei yloc
  831.         pei dlgwptr+2
  832.         pei dlgwptr
  833.         _FindControl
  834.         pla
  835.         beq MDnoBeep          ;Missed all of the controls.    
  836.  
  837.         jsr fixLEflash
  838.  
  839.         pha
  840.         pei xloc
  841.         pei yloc
  842.         lda #-1
  843.         pha
  844.         pha
  845.         pei ctlHndl+2
  846.         pei ctlHndl
  847.         _TrackControl
  848.         pla
  849.         sta >ctlPart
  850.         beq MDnoBeep
  851.  
  852.         ldy #owmTaskData2     ;Put the found control in TaskData2
  853.         lda ctlHndl           ;for application.
  854.         sta [event],y
  855.         iny
  856.         iny
  857.         lda ctlHndl+2
  858.         sta [event],y
  859.         jsr setValues
  860.         clc
  861.         rts
  862.  
  863. MDBeep  lda beepProc+2
  864.         bmi MDnoBeep          ;Negative, do nothing.
  865.         ora beepProc
  866.         beq MDSysBeep         ;Zero, regular SysBeep.
  867.  
  868.         pei event+2           ;Give the custom "beep" something
  869.         pei event             ;to play with.
  870.         phk                   ;Push where we want to return to.
  871.         pea MDnoBeep-1
  872.         lda beepProc+1        ;Push updateProc addr and return to it.
  873.         pha
  874.         phb
  875.         pla
  876.         lda beepProc
  877.         dec a
  878.         pha
  879.         rtl
  880. MDSysBeep anop
  881.         _SysBeep
  882. MDnoBeep anop
  883.         clc
  884.         rts
  885.  
  886. fixLEflash anop
  887.         jsr getCtlProc
  888.         cmp #editLineControl|-16
  889.         bne FixLErts
  890.         ldy #octlMoreFlags
  891.         lda [ctlPtr],y
  892.         bmi FixLErts          ;LineEdit control already target.
  893.  
  894.         ldy #octlData         ;For lineEdit controls that are
  895.         lda [ctlPtr],y        ;inactive, make sure that there is no
  896.         sta theHndl           ;text currently selected.  If there is,
  897.         iny                   ;TrackControl will temporarily flash
  898.         iny                   ;the selected range.  So, we check to
  899.         lda [ctlPtr],y        ;see if we are a lineEdit control.  If
  900.         sta theHndl+2         ;we are, we see if we are active.  If
  901.         ldy #2                ;we aren't, we set selEnd to be the
  902.         lda [theHndl]         ;same as selStart.  Simple, huh?
  903.         sta thePtr
  904.         lda [theHndl],y
  905.         sta thePtr+2
  906.  
  907.         ldy #oleSelStart     ;thePtr is deref'ed lineEdit record.
  908.         lda [thePtr],y       ;Set selEnd to be the same as selStart.
  909.         iny
  910.         iny
  911.         sta [thePtr],y       ;It is done.  It is good.  The end.
  912.  
  913. FixLErts anop
  914.         rts
  915.  
  916. ***
  917.  
  918. fmdGetCtlPart entry
  919. FMDGETCTLPART entry
  920.         lda >ctlPart
  921.         sta 4,s
  922.         jml _fmdNoError
  923. ctlPart dc i'0'
  924.  
  925. ***
  926.  
  927. setValues anop
  928.         pha                  ;Convert the control handle into an ID
  929.         pha                  ;for application.
  930.         pei ctlHndl+2
  931.         pei ctlHndl
  932.         _GetCtlID
  933.         pla
  934.         ply
  935.         bcs FMDTemp15        ;List controls have non-super-control
  936. *                            ;scrollbars.  We therefore don't want
  937. *                            ;to return a control-id here, since
  938. *                            ;non-super-controls don't have an id to
  939. *                            ;return anyway.  (We get an error $1007
  940. *                            ;if it isn't a super-control, so we
  941. *                            ;don't want to return anything
  942. *                            ;anything, since it garbage.)
  943.         sta retval
  944.         sty retval+2         ;Return the ctlID in retval.
  945.  
  946. FMDTemp15 anop
  947.         jsr getCtlProc       ;See if radio button or checkbox.
  948.         cmp #radioControl|-16
  949.         beq radioButtonHit
  950.         cmp #checkControl|-16
  951.         bne SetValuesRts
  952.  
  953. CheckBoxHit anop
  954.         pha
  955.         pei ctlHndl+2
  956.         pei ctlHndl
  957.         _GetCtlValue
  958.         pla
  959.         beq FMDTemp16         ;Do a true NOT.
  960.         lda #$FFFF
  961. FMDTemp16 anop
  962.         inc a
  963. FMDTemp17 anop
  964.         pha
  965.         pei ctlHndl+2
  966.         pei ctlHndl
  967.         _SetCtlValue
  968. SetValuesRts anop
  969.         rts
  970.  
  971. radioButtonHit anop
  972.         lda #1
  973.         bra FMDTemp17
  974.  
  975. doMenuTask anop
  976.         clc
  977. doMenuTaskz anop
  978.         php                   ;Keep carry status.
  979.         pei event+2
  980.         pei event
  981.         lda #0
  982.         pha
  983.         pha
  984.         bcs FMDTemp19
  985.         jsr ibeamTest
  986.         bcc FMDTemp18
  987.         _InitCursor           ;This only gets done if it is currently
  988. *                             ;an ibeam.
  989. FMDTemp18 anop
  990.         _MenuSelect           ;Handle the pullDown.
  991.         bra FMDTemp20
  992. FMDTemp19 anop
  993.         _MenuKey              ;Handle the menu key.
  994.  
  995. FMDTemp20 anop
  996.         plp                   ;Restore carry status.
  997.         ldy #owmTaskData
  998.         lda [event],y
  999.         beq MenuTaskRts       ;PullDown, cclear.  MenuKey, cset.
  1000.         tax
  1001.         iny
  1002.         iny
  1003.         lda [event],y
  1004.         sta menunum
  1005.  
  1006.         cpx #250              ;See if we should open a DA.
  1007.         bcs FMDTemp21
  1008.  
  1009.         lda flags             ;See if we should handle DA's.
  1010.         and #fmdDeskAcc
  1011.         beq FMDTemp23         ;No, hilite menu to normal.
  1012.         phx                   ;Open the can-o-worms.
  1013.         phx
  1014.         _InitCursor
  1015.         _OpenNDA
  1016.         pla
  1017.         bra FMDTemp23         ;Do _HiliteMenu and leave.
  1018.  
  1019. FMDTemp21 anop
  1020.         cpx #256              ;Anything above close, let app do it.
  1021.         bcs FMDTemp24         ;Not an undo/cut/copy/paste/clear/close
  1022. *                             ;menu item.
  1023.  
  1024.         ldy wkind
  1025.         bpl FMDTemp22
  1026.  
  1027.         cpx #255
  1028.         beq CloseNDA          ;Go let the DA handle it.
  1029.  
  1030.         txa
  1031.         sec
  1032.         sbc #249
  1033.         pha
  1034.         pha
  1035.         _SystemEdit
  1036.         pla
  1037.         bra FMDTemp23         ;Do _HiliteMenu and leave.
  1038.  
  1039. FMDTemp22 anop
  1040.         cpx #255
  1041.         beq FMDTemp24         ;Let app do close for non DA windows.
  1042.         cpx #250
  1043.         beq FMDTemp24         ;Let app do undo also.
  1044.  
  1045.         stx editTask          ;Let cut/copy/paste know what to do.
  1046.         jsr doCutCopyPaste
  1047.  
  1048. FMDTemp23 anop
  1049.         pei zero
  1050.         pei menunum
  1051.         _HiliteMenu
  1052.         clc
  1053.         rts
  1054.  
  1055. FMDTemp24 anop
  1056.         stx retval            ;Low-order word contains the ID # of
  1057.         ora #$8000            ;item selected.  Hi-order word contains
  1058.         sta retval+2          ;the menu ID # with hi-bit turned on.
  1059.         clc                   ;The hi-bit is to allow the application
  1060. *                             ;to distinguish this from a control ID.
  1061. *                             ;This means ID's must be hi-bit off!!
  1062. MenuTaskRts rts
  1063.  
  1064. CloseNDA anop
  1065.         pha
  1066.         pha
  1067.         _FrontWindow
  1068.         lda 1,s               ;Be extra paranoid -- it helps.
  1069.         cmp keepPort          ;Make sure that the desk accessory was
  1070.         bne FMDTemp21b        ;not active port when fakeModalDialog
  1071.         lda 3,s               ;was called.  If it is, we will get
  1072.         cmp keepPort+2        ;into trouble closing it, because we
  1073.         bne FMDTemp21b        ;will do a SetPort to keepPort when we
  1074.         lda dlgwptr           ;leave.  So, if keepPort is the port we
  1075.         sta keepPort          ;are about to close, change it to the
  1076.         lda dlgwptr+2         ;dlgwptr (the app's dialog window).
  1077.         sta keepPort+2
  1078. FMDTemp21b anop
  1079.         _CloseNDAByWinPtr
  1080.         bra FMDTemp23
  1081.  
  1082. isMyWindow anop
  1083.         lda whichWindow
  1084.         cmp dlgwptr
  1085.         bne NotMyWindow
  1086.         lda whichWindow+2
  1087.         cmp dlgwptr+2
  1088.         beq YesMyWindow
  1089. NotMyWindow anop
  1090.         clc
  1091. YesMyWindow anop
  1092.         rts
  1093.  
  1094. ***
  1095.  
  1096. doMenuKey anop
  1097.         lda code
  1098.         cmp #keyDownEvt
  1099.         beq FMDTemp22a
  1100.         sec
  1101. MenuKeyRts anop
  1102.         rts                   ;It isn't a menu key, since it isn't
  1103. *                             ;even a key.
  1104.  
  1105. FMDTemp22a anop
  1106.         lda flags
  1107.         and #fmdMenuKey
  1108.         sec
  1109.         beq MenuKeyRts        ;Menu keys not allowed (carry is set).
  1110.  
  1111.         brl doMenuTaskz       ;Carry still set, which is important.
  1112.  
  1113. ***
  1114.  
  1115. ibeamTest anop
  1116.         lda wkind
  1117.         clc
  1118.         bmi IBeamRts          ;Don't do our ibeam when a DA is up.
  1119.         pha                   ;This is so we know what cursor we
  1120.         pha                   ;currently have.  Otherwise, we will be
  1121.         _GetCursorAdr         ;setting the cursor a lot, and it will
  1122.         pha                   ;flash.
  1123.         pha
  1124.         jsl fmdGetIBeamAdr    ;This clears carry (no error returned.)
  1125.         pla
  1126.         ply
  1127.         eor 1,s
  1128.         bne NoIBeam           ;Carry is clear.
  1129.         tya
  1130.         eor 3,s
  1131.         bne NoIBeam           ;Carry is clear.
  1132.         sec
  1133. NoIBeam pla
  1134.         pla
  1135. IBeamRts anop
  1136.         rts                   ;Carry set means we now have ibeam.
  1137.  
  1138.         End
  1139.  
  1140.  
  1141. *******************************************************************************
  1142. *******************************************************************************
  1143. *******************************************************************************
  1144.  
  1145. * From this point are additional entry points and useful access routines.
  1146.  
  1147. ********************
  1148.  
  1149. fmdStdDrawProc Start
  1150.  
  1151. FMDSTDDRAWPROC entry
  1152.         pha                   ;What kind of window frame do we want?
  1153.         pha
  1154.         pha
  1155.         _GetPort
  1156.         _GetWFrame
  1157.         pla                   ;fAlert is bit 13.  fFlex is bit 9.
  1158.         asl a
  1159.         asl a                 ;fAlert is now in bit 15.
  1160.         bmi StdNoFrame        ;We already have a frame, and
  1161. *                             ;it looks maaahvelous!
  1162.  
  1163.         and #$0800            ;Bit 9 moved into bit 11.
  1164.         bne StdNoFrame
  1165.  
  1166.         pha
  1167.         _GetMasterSCB
  1168.         pla
  1169.         xba
  1170.         asl a
  1171.         lda #5
  1172.         bcs in640
  1173.         lsr a
  1174. in640   pha                   ;Keep the width for _InsetRect.
  1175.         pha                   ;Push the width for _FrameRect.
  1176.         pea 2
  1177.         _SetPenSize
  1178.         plx                   ;The width for _InsetRect.
  1179.         lda #StdworkRect
  1180.         ldy #StdworkRect|-16
  1181.         phy                   ;Push parameters for _FrameRect.
  1182.         pha
  1183.         phy                   ;Push parameters for _InsetRect.
  1184.         pha
  1185.         phx                   ;Push the width for _InsetRect.
  1186.         pea 2
  1187.         phy                   ;Push parameters for _GetPortRect.
  1188.         pha
  1189.         _GetPortRect
  1190.         _InsetRect
  1191.         _FrameRect
  1192.         _PenNormal
  1193.  
  1194. StdNoFrame anop
  1195.         pha
  1196.         pha
  1197.         _GetPort
  1198.         _DrawControls
  1199.         rtl
  1200.  
  1201. StdworkRect ds 8
  1202.  
  1203.         End
  1204.  
  1205. ********************
  1206.  
  1207. fmdSetMenuProc Start
  1208.  
  1209. FMDSETMENUPROC entry
  1210.         lda 4,s
  1211.         sta >menuProc
  1212.         lda 6,s
  1213.         sta >menuProc+2
  1214.         lda 1,s
  1215.         sta 5,s
  1216.         lda 2,s
  1217.         sta 6,s
  1218.         pla
  1219.         pla
  1220. exit    jml _fmdNoError
  1221.  
  1222. fmdGetMenuProc entry
  1223. FMDGETMENUPROC entry
  1224.         lda >menuProc
  1225.         sta 4,s
  1226.         lda >menuProc+2
  1227.         sta 6,s
  1228.         bra exit
  1229.  
  1230. menuProc dc i4'0'
  1231.  
  1232.         End
  1233.  
  1234. ********************
  1235.  
  1236. fmdEditMenu     Start
  1237.  
  1238.                 DefineStack
  1239.  
  1240. selStart        long
  1241. selEnd          long
  1242. leHndl          long
  1243. lePtr           long
  1244. ctlPtr          long          ;Must be 2nd from end of local space.
  1245. ctlHndl         long          ;Must be at end of local space.
  1246.  
  1247. sizeEditLocals  EndLocals
  1248.  
  1249. saveDPage       word
  1250. returnAddr      block 3
  1251.  
  1252. ***
  1253.  
  1254. FMDEDITMENU entry
  1255.         phd                   ;Save directPage register.
  1256.  
  1257.         tsc                   ;Make space for locals, part 1.
  1258.         sec
  1259.         sbc #sizeEditLocals
  1260.         tcd
  1261.  
  1262.         pha                   ;Find out if it is a DA window.
  1263.         pha
  1264.         pha
  1265.         _FrontWindow
  1266.         _GetWKind
  1267.         pla
  1268.         bpl FMDTemp23         ;It is a regular window.
  1269.         pea 250
  1270.         _EnableMItem          ;Enable undo.
  1271.         pea 255
  1272.         _EnableMItem          ;Enable close.
  1273.         ldx #%1111            ;Enable cut/copy/paste/clear.
  1274.         brl EMSetMenus
  1275.  
  1276. FMDTemp23 anop
  1277.         pha
  1278.         pha
  1279.         _FindTargetCtl
  1280.         bcc FMDTemp23a        ;There is a target, so go do some work.
  1281.         brl EMnoTool
  1282.  
  1283. FMDTemp23a anop
  1284.         ldy #2                ;Deref target ctl handle into ctlPtr.
  1285.         lda [ctlHndl],y
  1286.         pha
  1287.         lda [ctlHndl]
  1288.         pha
  1289.  
  1290.         tdc                   ;Make space for locals, part 2.
  1291.         tcs                   ;Stack ptr & directPage ptr agree now.
  1292.  
  1293.         ldy #octlProc+2       ;Get hi-word of Proc address.
  1294.         lda [ctlPtr],y
  1295.  
  1296.  
  1297.         cmp #editTextControl|-16
  1298.         beq EMTextEdit        ;It is TextEdit tool.
  1299.         cmp #editLineControl|-16
  1300.         bne EMnoTool          ;Not LineEdit tool.
  1301.  
  1302. EMLineEdit anop
  1303.         ldy #octlData         ;Get the lineEdit handle from
  1304.         lda [ctlPtr],y        ;the control's data field.
  1305.         sta leHndl
  1306.         iny
  1307.         iny
  1308.         lda [ctlPtr],y
  1309.         sta leHndl+2
  1310.  
  1311.         ldy #2                ;Dereference leHndl.
  1312.         lda [leHndl]
  1313.         sta lePtr
  1314.         lda [leHndl],y
  1315.         sta lePtr+2
  1316.  
  1317.         ldx #0
  1318.         jsr canWePaste
  1319.  
  1320.         ldy #oleSelStart
  1321.         lda [lePtr],y
  1322.         iny
  1323.         iny
  1324.         cmp [lePtr],y
  1325.         beq EMSetMenus
  1326.         txa
  1327.         ora #%1011            ;Enable cut/copy/clear.
  1328.         tax     
  1329.         bra EMSetMenus
  1330.  
  1331. EMTextEdit anop
  1332.         ldy #0
  1333.         phy
  1334.         tdc
  1335.         clc
  1336.         adc #selStart
  1337.         pha
  1338.         phy
  1339.         adc #selEnd-selStart
  1340.         pha
  1341.         pei ctlHndl+2
  1342.         pei ctlHndl
  1343.         _TEGetSelection
  1344.         ldx #%1011
  1345.         lda selStart
  1346.         cmp selEnd
  1347.         bne EMhasSelect
  1348.         lda selStart+2
  1349.         cmp selEnd+2
  1350.         bne EMhasSelect
  1351.         ldx #0
  1352.  
  1353. EMhasSelect anop
  1354.         jsr canWePaste
  1355.  
  1356.         ldy #$28+2            ;Find out if we are read-only.
  1357.         lda [ctlPtr],y
  1358.         and #$0400            ;Bit 26, please.
  1359.         beq EMSetMenus
  1360.  
  1361.         txa                   ;Don't allow cut & paste.
  1362.         and #2
  1363.         tax
  1364.         bra EMSetMenus
  1365.  
  1366. EMnoTool anop
  1367.         ldx #0                ;Bit 0 for cut, 1 for copy,
  1368. *                             ;2 for paste.
  1369. EMSetMenus anop
  1370.         txa
  1371.         ldy #251
  1372.         jsr setOneMenu
  1373.         jsr setOneMenu
  1374.         jsr setOneMenu
  1375.         jsr setOneMenu
  1376.  
  1377. EMExit  tdc                   ;Remove local space.
  1378.         clc
  1379.         adc #sizeEditLocals
  1380.         tcs
  1381.         pld                   ;Restore directPage register.
  1382.         jml _fmdNoError
  1383.  
  1384. setOneMenu anop
  1385.         lsr a
  1386.         pha
  1387.         phy
  1388.         phy
  1389.         bcs SetEnable
  1390. SetDisable anop
  1391.         _DisableMItem
  1392.         bra FMDTemp24
  1393. SetEnable anop
  1394.         _EnableMItem
  1395. FMDTemp24 anop
  1396.         ply
  1397.         iny
  1398.         pla
  1399.         rts
  1400.  
  1401. canWePaste anop
  1402.         txa                   ;Assume no paste.
  1403.         and #$FFFF-4
  1404.         pha
  1405.  
  1406.         pha                   ;See if paste should be available.
  1407.         pha
  1408.         pea 0
  1409.         _GetScrapSize
  1410.         plx
  1411.         ply
  1412.  
  1413.         pla                   ;Get cut/copy/paste status back.
  1414.  
  1415.         bcs PasteExit         ;Error, so no paste.
  1416.         phy
  1417.         ply
  1418.         bne YesWeCanPaste
  1419.         txy
  1420.         beq PasteExit
  1421. YesWeCanPaste anop
  1422.         ora #4
  1423.  
  1424. PasteExit anop
  1425.         tax
  1426.         rts
  1427.  
  1428.         End
  1429.  
  1430. ********************
  1431.  
  1432. fmdFindCursorCtl Start
  1433.  
  1434.                  DefineStack
  1435.  
  1436. hndl             long         ;Must be at 1,s
  1437. ctlHndl          long
  1438. ctlPtr           long
  1439.  
  1440. sizeCursorLocals EndLocals
  1441.  
  1442. saveDPage        word
  1443. returnAddr       block 3
  1444.  
  1445.                  BegParms
  1446. wptr             long
  1447. yloc             word
  1448. xloc             word
  1449. ctlHndlPtr       long         ;Where to store the control handle.
  1450. sizeCursorParms  Endparms
  1451.  
  1452. ctlPart          word
  1453.  
  1454. ***
  1455.  
  1456. FMDFINDCURSORCTL entry
  1457.         phd                   ;Save directPage register.
  1458.         tsc                   ;Make space for locals.
  1459.         sec
  1460.         sbc #sizeCursorLocals
  1461.         tcs
  1462.         tcd                   ;Set directPage register.
  1463.  
  1464.         pei wptr+2
  1465.         pei wptr
  1466.         _GetWControls         ;Result space already there (hndl).
  1467.  
  1468.         stz ctlPart           ;Assume failure.
  1469.         stz ctlHndl
  1470.         stz ctlHndl+2
  1471.  
  1472. FMDLoop2 anop
  1473.         lda hndl+1
  1474.         beq FindCursorExit    ;No more controls to check.
  1475.  
  1476.         ldy #2                ;Deref hndl.
  1477.         lda [hndl]
  1478.         sta ctlPtr
  1479.         lda [hndl],y
  1480.         sta ctlPtr+2
  1481.  
  1482.         pha                   ;Result space for _PtInRect
  1483.         pea 0                 ;Push pointer to point.
  1484.         tdc
  1485.         clc
  1486.         adc #yloc
  1487.         pha
  1488.         lda ctlPtr            ;Push ptr to bounding rect of ctl.
  1489.         clc
  1490.         adc #octlRect
  1491.         tax
  1492.         lda ctlPtr+2
  1493.         adc #0
  1494.         pha
  1495.         phx
  1496.         _PtInRect
  1497.         pla
  1498.         beq FindCursorNextCtl
  1499.  
  1500.         sta ctlPart
  1501.         lda hndl              ;Copy the temp hndl to the "real" one.
  1502.         sta ctlHndl
  1503.         lda hndl+2
  1504.         sta ctlHndl+2
  1505.  
  1506.         ldy #octlProc+2       ;Get hi-word of Proc address.
  1507.         lda [ctlPtr],y
  1508.         cmp #editTextControl|-16
  1509.         bne FindCursorExit
  1510.  
  1511. FindCursorNextCtl anop
  1512.         ldy #2
  1513.         lda [ctlPtr]          ;Get the next control handle.
  1514.         sta hndl
  1515.         lda [ctlPtr],y
  1516.         sta hndl+2
  1517.         bra FMDLoop2
  1518.  
  1519. FindCursorExit anop
  1520.         lda ctlHndl           ;Return the ctl hndl (could be NULL).
  1521.         sta [ctlHndlPtr]
  1522.         lda ctlHndl+2
  1523.         ldy #2
  1524.         sta [ctlHndlPtr],y
  1525.  
  1526.         tsc                   ;Get rid of local variables.
  1527.         clc
  1528.         adc #sizeCursorLocals
  1529.         tcs
  1530.         pld                   ;Restore directPage register.
  1531.         lda 1,s               ;Move return address.
  1532.         sta 1+sizeCursorParms,s
  1533.         lda 2,s
  1534.         sta 2+sizeCursorParms,s
  1535.         tsc                   ;Get rid of passed parameters.
  1536.         adc #sizeCursorParms
  1537.         tcs
  1538.         jml _fmdNoError
  1539.  
  1540.         End
  1541.  
  1542. ********************
  1543.  
  1544. * Here are some useful routines for control information access via a ctl ID.
  1545.  
  1546. ********************
  1547.  
  1548. * This routine takes a window pointer, a lineEdit control ID, and a pointer to
  1549. * a pascal string.  It stuffs the pascal string into the lineEdit control.
  1550. * It also select the full range of the text.  This is useful because the
  1551. * target control should have all the text selected when a dialog comes up.
  1552. * Doing it here means you don't have to do it elsewhere.
  1553.  
  1554. fmdLESetText    Start
  1555.  
  1556.                 DefineStack
  1557.  
  1558. ctlHndl         long    
  1559. ctlPtr          long    
  1560. leHndl          long    
  1561. lePtr           long    
  1562. lineHndl        long    
  1563. linePtr         long    
  1564. cstr            long    
  1565. lineLength      word
  1566. rect            block 8       ;Must be > oleViewRect ($10)
  1567.  
  1568. sizeLESetLocals EndLocals
  1569.  
  1570. saveDPage       word
  1571. returnAddr      block 3
  1572.  
  1573.                 BegParms
  1574. pstr            long          ;Pointer to string space.
  1575. lineEditID      long          ;ID of lineEdit control.
  1576. wptr            long          ;Window that owns the control.
  1577. sizeLESetParms  Endparms
  1578.  
  1579. ***
  1580.  
  1581. FMDLESETTEXT entry
  1582.         jsr lineEditSetup     ;Set up everything we need.
  1583.         bcs exit              ;Couldn't dereference for some reason.
  1584.  
  1585.         pei cstr+2            ;Set text to c-string.
  1586.         pei cstr
  1587.         lda [pstr]            ;Get length of pascal string.
  1588.         and #$FF
  1589.         pha
  1590.         pei leHndl+2
  1591.         pei leHndl
  1592.         _LESetText
  1593.         bcs exit
  1594.  
  1595.         pha                   ;Invalidate view rect of lineEdit.
  1596.         pha
  1597.         _GetPort              ;Save the current port.
  1598.         pei wptr+2
  1599.         pei wptr
  1600.         _SetPort              ;Make the window the current port
  1601. *                             ;(for _InvalRect).
  1602.  
  1603.         jsr lineEditDeref     ;Redereference -- slow but small.
  1604.         ldy #oleSelStart
  1605.         lda #0
  1606.         pha                   ;Hi-word for _InvalRect.
  1607.         sta [lePtr],y
  1608.         iny
  1609.         iny                   ;Point at leSelEnd.
  1610.         lda [pstr]            ;Get length of pascal string.
  1611.         and #$FF
  1612.         sta [lePtr],y
  1613.  
  1614.         ldy #oleViewRect+6    ;Copy lineEdit viewRect into rect.
  1615. FMDTemp25 anop
  1616.         lda [lePtr],y
  1617.         tyx
  1618.         sta <rect-oleViewRect,x
  1619.         dey
  1620.         dey
  1621.         cpy #oleViewRect
  1622.         bcs FMDTemp25
  1623.  
  1624.         tdc                   ;Hi-word alreay on stack.  (It's a 0).
  1625.         adc #rect             ;Carry still clear.
  1626.         pha
  1627.         _InvalRect            ;Inval that rect.
  1628.  
  1629.         _SetPort              ;Put the port back.
  1630.  
  1631. exitNoErr anop
  1632.         lda #0                ;Return no error.
  1633. exit    tay                   ;Save error code.
  1634.  
  1635.         tdc                   ;Get rid of local variables.
  1636.         clc
  1637.         adc #sizeLESetLocals
  1638.         tcs
  1639.         pld                   ;Restore directPage register.
  1640.  
  1641.         lda 1,s               ;Move return address.
  1642.         sta 1+sizeLESetParms,s
  1643.         lda 2,s
  1644.         sta 2+sizeLESetParms,s
  1645.  
  1646.         tsc                   ;Pull passed parms off stack.
  1647.         adc #sizeLESetParms
  1648.         tcs
  1649.  
  1650.         tya                   ;Recover error code.
  1651.         jml _fmdSetError
  1652.  
  1653. ***
  1654.  
  1655. fmdLEGetText entry
  1656. FMDLEGETTEXT entry
  1657.         jsr lineEditSetup     ;Set up everything we need.
  1658.         bcs exit              ;Couldn't dereference for some reason.
  1659.  
  1660.         pei linePtr+2         ;Copy the text into the string.
  1661.         pei linePtr
  1662.         pei cstr+2
  1663.         pei cstr
  1664.         pea 0
  1665.         pei lineLength
  1666.         _BlockMove
  1667.  
  1668.         ldy lineLength        ;Store the p-string length and also
  1669.         tya                   ;terminate the string for the c dudes.
  1670.         shortm                ;Use 8-bit accumulator.
  1671.         sta [pstr]            ;Save the p-string length byte.
  1672.         lda #0
  1673.         sta [cstr],y          ;Terminate the c-string.
  1674.         longm                 ;Set accumulator back to 16-bit.
  1675.  
  1676.         bra exitNoErr         ;Return no error.
  1677.  
  1678. ***
  1679.  
  1680. lineEditSetup anop
  1681.         plx                   ;Save return address so stack frame
  1682. *                             ;setup works.
  1683.  
  1684.         phd                   ;Save directPage register.
  1685.         tsc                   ;Make space for locals.
  1686.         sec
  1687.         sbc #sizeLESetLocals
  1688.         tcs
  1689.         tcd                   ;Set directPage register.
  1690.  
  1691.         phx                   ;Put return address back.
  1692.  
  1693.         lda pstr              ;Also point past p-string length
  1694.         ldx pstr+2            ;for c-strings.
  1695.         inc a
  1696.         bne FMDTemp26
  1697.         inx
  1698. FMDTemp26 anop
  1699.         sta cstr
  1700.         stx cstr+2
  1701.  
  1702.         pha                   ;Get the control handle via wptr,id.
  1703.         pha
  1704.         pei wptr+2
  1705.         pei wptr
  1706.         pei lineEditID+2
  1707.         pei lineEditID
  1708.         _GetCtlHandleFromID
  1709.         plx
  1710.         stx ctlHndl
  1711.         plx
  1712.         stx ctlHndl+2
  1713.         bcs rts1
  1714.  
  1715.         ldy #2                ;Dereference ctlHndl.
  1716.         lda [ctlHndl]
  1717.         sta ctlPtr
  1718.         lda [ctlHndl],y
  1719.         sta ctlPtr+2
  1720.  
  1721.         ldy #octlData         ;Get the lineEdit handle from
  1722.         lda [ctlPtr],y        ;the control's data field.
  1723.         sta leHndl
  1724.         iny
  1725.         iny
  1726.         lda [ctlPtr],y
  1727.         sta leHndl+2
  1728.  
  1729. lineEditDeref anop
  1730.         ldy #2                ;Dereference leHndl.
  1731.         lda [leHndl]
  1732.         sta lePtr
  1733.         lda [leHndl],y
  1734.         sta lePtr+2
  1735.  
  1736.         ldy #oleLength
  1737.         lda [lePtr],y
  1738.         sta lineLength
  1739.  
  1740.         ldy #oleLineHandle
  1741.         lda [lePtr],y
  1742.         sta lineHndl
  1743.         iny
  1744.         iny
  1745.         lda [lePtr],y
  1746.         sta lineHndl+2
  1747.  
  1748.         ldy #2                ;Dereference lineHndl.
  1749.         lda [lineHndl]
  1750.         sta linePtr
  1751.         lda [lineHndl],y
  1752.         sta linePtr+2
  1753.         clc                   ;Everything worked.
  1754.  
  1755. rts1    rts
  1756.  
  1757.         End
  1758.  
  1759. ********************
  1760.  
  1761. fmdWhichRadio   Start
  1762.  
  1763.                 DefineStack
  1764.  
  1765. ctlHndl         long          ;Must be at 1,s
  1766. ctlPtr          long    
  1767. ctlID           long          ;ID of some radio button control.
  1768. theRadBut       word
  1769. notHere         word          ;Flag for active button not found.
  1770.  
  1771. sizeWRLocals    EndLocals
  1772.  
  1773. saveDPage       word
  1774. returnAddr      block 3
  1775.  
  1776.                 BegParms
  1777. famNum          word
  1778. wptr            long          ;Window that owns the control.
  1779. sizeWRParms     Endparms
  1780.  
  1781. radioNum        word
  1782.  
  1783. ***
  1784.  
  1785. FMDWHICHRADIO entry
  1786.         phd                   ;Save directPage register.
  1787.         tsc                   ;Make space for locals.
  1788.         sec
  1789.         sbc #sizeWRLocals
  1790.         tcs
  1791.         tcd                   ;Set directPage register.
  1792.  
  1793.         lda #$FFFF            ;This is supposed to be a bogus value
  1794.         sta radioNum          ;(0 is legit).
  1795.         sta notHere           ;Assume we won't find active radio
  1796.         sta ctlID+2           ;button of correct family number.
  1797.  
  1798.         pei wptr+2
  1799.         pei wptr
  1800.         _GetWControls         ;Result space already there (ctlHndl).
  1801.         bcs WhichRadioExit
  1802.  
  1803. FMDLoop3 anop
  1804.         lda ctlHndl+1         ;See if we have a NULL handle yet.
  1805.         beq FMDEndLoop3
  1806.  
  1807.         jsr WRDerefCtl        ;Deref ctlHndl into ctlPtr.
  1808.  
  1809.         ldy #octlProc+2       ;Get hi-word of Proc address.
  1810.         lda [ctlPtr],y
  1811.         cmp #radioControl|-16
  1812.         bne WRNextCtl         ;Not a radio button.  Skip it.
  1813.  
  1814.         ldy #octlFlag
  1815.         lda [ctlPtr],y
  1816.         and #$7F
  1817.         cmp famNum            ;See if it is "our" family.
  1818.         bne WRNextCtl         ;Not related.
  1819.  
  1820.         ldy #octlID+2         ;See if this is the smallest ctlID for
  1821.         lda [ctlPtr],y        ;our family yet.
  1822.         tax
  1823.         dey
  1824.         dey
  1825.         lda [ctlPtr],y
  1826.         cpx ctlID+2
  1827.         bcc wrSmaller
  1828.         bne wrNotSmall        ;It isn't.
  1829.         cmp ctlID
  1830.         bcs wrNotSmall        ;It isn't.
  1831. wrSmaller anop                ;It is, so remember it.
  1832.         sta ctlID
  1833.         stx ctlID+2
  1834.  
  1835. wrNotSmall anop
  1836.         tax
  1837.         ldy #octlValue
  1838.         lda [ctlPtr],y
  1839.         beq WRNextCtl         ;This isn't the active radio button.
  1840.         stx theRadBut         ;This is the one, so remember enough
  1841.         stz notHere           ;of it.
  1842.  
  1843. WRNextCtl anop
  1844.         ldy #2
  1845.         lda [ctlPtr]
  1846.         sta ctlHndl
  1847.         lda [ctlPtr],y
  1848.         sta ctlHndl+2
  1849.         bra FMDLoop3
  1850.  
  1851. FMDEndLoop3 anop
  1852.         lda notHere
  1853.         bmi wrFail
  1854.         lda theRadBut
  1855.         sec
  1856.         sbc ctlID
  1857. wrFail  sta radioNum          ;This is what the programmer was
  1858. *                             ;yearning for.
  1859.  
  1860.         lda #0                ;Return no error.
  1861.  
  1862. WhichRadioExit anop
  1863.         tay                   ;Save error code.
  1864.  
  1865.         tdc                   ;Get rid of local variables.
  1866.         clc
  1867.         adc #sizeWRLocals
  1868.         tcs
  1869.         pld                   ;Restore directPage register.
  1870.  
  1871.         lda 1,s               ;Move return address.
  1872.         sta 1+sizeWRParms,s
  1873.         lda 2,s
  1874.         sta 2+sizeWRParms,s
  1875.  
  1876.         tsc                   ;Pull passed parms off stack.
  1877.         adc #sizeWRParms
  1878.         tcs
  1879.  
  1880.         tya                   ;Recover error code.
  1881.         jml _fmdSetError
  1882.  
  1883. WRDerefCtl anop
  1884.         ldy #2
  1885.         lda [ctlHndl]
  1886.         sta ctlPtr
  1887.         lda [ctlHndl],y
  1888.         sta ctlPtr+2
  1889.         rts
  1890.  
  1891.         End
  1892.  
  1893. ********************
  1894.  
  1895. fmdIBeamCursor Start
  1896.  
  1897. FMDIBEAMCURSOR entry
  1898.         lda >curIBeam+2       ;Change the cursor to current ibeam.
  1899.         pha
  1900.         lda >curIBeam
  1901.         pha
  1902.         _SetCursor
  1903.         bra exit
  1904.  
  1905. fmdInitIBeam entry
  1906. FMDINITIBEAM entry
  1907.         lda #ibeamCursor      ;Make default ibeam current ibeam.
  1908.         sta >curIBeam
  1909.         lda #ibeamCursor|-16
  1910.         sta >curIBeam+2
  1911.         bra exit
  1912.  
  1913. fmdGetIBeamAdr entry
  1914. FMDGETIBEAMADR entry
  1915.         lda >curIBeam         ;Return address of current ibeam.
  1916.         sta 4,s
  1917.         lda >curIBeam+2
  1918.         sta 6,s
  1919.         bra exit
  1920.  
  1921. fmdSetIBeam entry
  1922. FMDSETIBEAM entry
  1923.         lda 4,s               ;Change the ibeam to alternate ibeam.
  1924.         sta >curIBeam
  1925.         lda 6,s
  1926.         sta >curIBeam+2
  1927.         lda 1,s
  1928.         sta 5,s
  1929.         lda 2,s
  1930.         sta 6,s
  1931.         pla
  1932.         pla
  1933. exit    jml _fmdNoError
  1934.  
  1935. curIBeam    dc i4'0'
  1936. ibeamCursor dc i1'9,0,3,0'
  1937.         dc i1'$00,$F0,$F0,$00,$00,$00'
  1938.         dc i1'$00,$0F,$00,$00,$00,$00'
  1939.         dc i1'$00,$0F,$00,$00,$00,$00'
  1940.         dc i1'$00,$0F,$00,$00,$00,$00'
  1941.         dc i1'$00,$0F,$00,$00,$00,$00'
  1942.         dc i1'$00,$0F,$00,$00,$00,$00'
  1943.         dc i1'$00,$0F,$00,$00,$00,$00'
  1944.         dc i1'$00,$0F,$00,$00,$00,$00'
  1945.         dc i1'$00,$F0,$F0,$00,$00,$00'
  1946. *                
  1947.         dc i1'$00,$00,$00,$00,$00,$00'
  1948.         dc i1'$00,$00,$00,$00,$00,$00'
  1949.         dc i1'$00,$00,$00,$00,$00,$00'
  1950.         dc i1'$00,$00,$00,$00,$00,$00'
  1951.         dc i1'$00,$00,$00,$00,$00,$00'
  1952.         dc i1'$00,$00,$00,$00,$00,$00'
  1953.         dc i1'$00,$00,$00,$00,$00,$00'
  1954.         dc i1'$00,$00,$00,$00,$00,$00'
  1955.         dc i1'$00,$00,$00,$00,$00,$00'
  1956.         dc i1'4,0,6,0'
  1957.  
  1958.         End
  1959.  
  1960. ********************
  1961.  
  1962. fmdStartUp Start
  1963.  
  1964. FMDSTARTUP entry
  1965.         lda #0
  1966.         pha
  1967.         pha
  1968.         jsl fmdSetMenuProc
  1969.         jml fmdInitIBeam
  1970.  
  1971.         End
  1972.  
  1973. ********************
  1974.  
  1975. fmdShutDown Start
  1976.  
  1977. FMDSHUTDOWN entry
  1978.         jml _fmdNoError
  1979.  
  1980.         End
  1981.  
  1982. ********************
  1983.  
  1984. _fmdNoError Start
  1985.  
  1986.         lda #0
  1987.  
  1988. _fmdSetError entry
  1989.         sta >fmdErr
  1990.         bra exit
  1991.  
  1992. fmdGetError entry
  1993.         lda >fmdErr
  1994.         sta 4,s
  1995. exit    cmp #1
  1996.         rtl
  1997.  
  1998. fmdErr  dc i'0'
  1999.  
  2000.         End
  2001.  
  2002. ********************
  2003.